﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class View_WMG_WMG007_1 : ViewMatrix
{
    bool isTopTen
    {
        get
        {
            if (ViewState["topten"] == null)
            {
                ViewState["topten"] = HttpContext.Current.Items["topten"];
            }
            return ViewState["topten"] == null
                ? false : true; ;
        }
    }
    bool showNext = true;
    string urlString = "../view/WMG/WMG007_1.aspx?t={0}";
    protected void Page_Load(object sender, EventArgs e)
    {
        limit();
        serviceName = "MISAPP.Classify.Service.Service_WMG007";
        criteriaList = new string[] { "Criteria", "type" };
        Title = "基金銷量分析表";
        if (Request.QueryString.Count.Equals(1))
        {
            Session["type"] = Request.QueryString[0].ToString();
            showNext = false;
        }


        if (!IsPostBack)
        {
            getData();  
        }
    }
    protected void getData()
    {
        string method = isTopTen.Equals(false) ? "GetSummaryData" : "GetTopTenData";

        System.Data.DataTable dt = GetDataFromSerevice(method);
        CLB_Summary.SetData(dt, new string[] { });

    }

    protected void CLB_Summary_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if ((e.Row.RowType == DataControlRowType.DataRow)
            & (!isTopTen))
        {
            if (e.Row.Cells[0].Text.Equals("合計"))
            { return; }
            if (e.Row.Cells[0].Text.IndexOf("小計") > 0)
            { return; }

            if (!showNext) return;

            string lnac_id;

            HyperLink link = new HyperLink();
            lnac_id = e.Row.Cells[0].Text;
            link.Text = e.Row.Cells[0].Text;
            link.NavigateUrl = string.Format(urlString, e.Row.Cells[0].Text);
            e.Row.Cells[0].Controls.Add(link);
        }    
    }

    protected void btn2Excel_Click(object sender, EventArgs e)
    {
        serviceName = "MISAPP.Classify.Service.Service_WMG007";
        //criteriaList = new string[] { "Criteria" };

        FillToSession();
        string pageParameter;
        if (!isTopTen)
        {
            pageParameter = string.Format(
                 "method=GetSummaryData&xls=WMG007&service=Service_WMG007&caption={0}&captionRight={1}&toHtmlMethod={2}"
                 , "基金銷售分析表", string.Empty, string.Empty);
        }
        else
        {
            pageParameter = string.Format(
                 "method=GetTopTenData&xls=WMG007&service=Service_WMG007&caption={0}&captionRight={1}&toHtmlMethod={2}"
                 , "TOP50基金銷售分析表", string.Empty, string.Empty);
        }

        btn2Excel.PreviousPage = "../GV2XLS.aspx";
        btn2Excel.PageParameter = pageParameter;
    }
}
